<?php

/**
 * @author Patricio Mac Adden <pmacadden@cespi.unlp.edu.ar>
 */
class WidgetFactory
{
  public static function replaceWidgets(sfForm $form)
  {
    foreach ($form->getWidgetSchema()->getFields() as $name => $widget)
    {
      if ($widget instanceof sfWidgetFormDate || $widget instanceof  sfWidgetFormDateTime)
      {
        $form->setWidget($name, self::getDateWidget());
      }

      if ($widget instanceof sfWidgetFormPropelChoice ){
        $widget->setOption('renderer_class', 'mbWidgetFormChosenChoice');
      }

      if ($widget instanceof sfWidgetFormFilterDate ){
        $form->setWidget($name, new sfWidgetFormFilterDate(array('from_date' => new mtWidgetFormInputDate(), 'to_date' => new mtWidgetFormInputDate(), 'with_empty' => false,'template'=> 'de %from_date% a %to_date%')));
        $form->setValidator($name, new sfValidatorDateRange(array('required' => false, 'from_date' => new mtValidatorDateString(array('required' => false)), 'to_date' => new mtValidatorDateString(array('required' => false)))));
      }




    }
  }

  public static function getDateWidget()
  {
    return new mtWidgetFormInputDate();
  }
}